package com.pj.viewpager.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import com.pj.viewpager.R;
import com.pj.viewpager.adapter.MyNewsListAdapter;
import com.pj.viewpager.bean.NewsListJavaBean;

import java.util.ArrayList;
import java.util.List;


public class NewsListFragment extends Fragment {


    private String title;
    private ListView newsList;
    private List<NewsListJavaBean> data;
    private int ImageId;

    public NewsListFragment(String title) {
        this.title = title;
        data = new ArrayList<>();
        switch (title){
            case "新闻":ImageId = R.drawable.news;break;
            case "美食":ImageId = R.drawable.food;break;
            case "运动":ImageId = R.drawable.football;break;
            case "医疗":ImageId = R.drawable.doctor;break;
            case "游戏":ImageId = R.drawable.game;break;
        }
        for (int i = 0; i < 10; i++) {
            data.add(new NewsListJavaBean(ImageId,title,"这是一条"+title+"列表项"));
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_news_list, container, false);
        initView(view);
        MyNewsListAdapter adapter = new MyNewsListAdapter(data);
        newsList.setAdapter(adapter);
        return view;
    }

    private void initView(View view) {
        newsList = (ListView) view.findViewById(R.id.news_list);
    }
}